package com.bite.ojsystem.controller;

import com.bite.ojcommonredis.service.RedisService;
import com.bite.ojsystem.domain.TestDomain;
import com.bite.ojsystem.domain.dto.ValidationDTO;
import com.bite.ojsystem.service.impl.TestService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/test")
@Tag(name = "测试接口类")
public class TestController {

    @Autowired
    private TestService testService;

    @Autowired
    private RedisService redisService;

    @GetMapping("/list")
    public List<TestDomain> list() {
//        int c = 1/0;
        List<TestDomain> list = testService.list();
        log.info("获得的数据列表 {}" ,list);
        return list;
    }

    @GetMapping("/redis")
    public String add() {
        redisService.setCacheObject("111","222");
        String object = redisService.getCacheObject("111", String.class);
        return  object;
    }

    @PostMapping("/validation")
    public String validation(@Validated @RequestBody ValidationDTO validationDTO) {
        log.info("后端参数校验 {} " ,validationDTO);
        return "参数校验测试";
    }

}
